// Using the closure to map jQuery to $. 
(function ($) {

// Store our function as a property of Drupal.behaviors.
Drupal.behaviors.deployment_validating = {
	attach: function(context, settings) {
		$("#progress-bar").progressbar({
			value: false
		});
		ticket_id = $("#ticket-id").val();
		pull_status(ticket_id);
		function pull_status(ticket_id) {
			$.ajax({
				url: 'deploymentget_package_status/'+ticket_id, 
				success: function(data) {
					switch (data) {
					case "0":
						break;
					case "1":			// validating
						break;
					case "2":		//failed
						break;
					case "3":			// pending
						window.location.replace('deployment/add_success/'+ticket_id);
						break;
					case "4":
						break;
					}
				},
				complete: function() {
					// Schedule the next request when the current one's complete
					setTimeout(function() {pull_status(ticket_id);}, 5000);
				},
			});
		}
	}
};
}(jQuery));